import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xin_nuo_pda/bean/lot_entity.dart';
import 'package:xin_nuo_pda/utils/string_extension.dart';
import 'package:xin_nuo_pda/values/colors.dart';
import 'package:xin_nuo_pda/values/constant.dart';
import 'package:xin_nuo_pda/views/SubTitleBar.dart';
import 'package:xin_nuo_pda/views/edittext/ClearEditText.dart';

import 'StartWorkNextDBController.dart';
import 'StartWorkNextOneController.dart';

class StartWorkNextDBPage extends StatelessWidget {
  final logic = Get.put(StartWorkNextDBController());
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(USER),
        ),
        body: SingleChildScrollView(
          child: GetBuilder<StartWorkNextDBController>(
            builder: (logic) => Container(
              child: Column(
                children: [
                  SubTitleBar("开始作业", '提交', () {
                      logic.trackIn();
                  }),
                  Container(
                    margin: EdgeInsets.all(8),
                    alignment: Alignment.centerLeft,
                    child: Text(
                      "主物料信息",
                      style:
                          TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
                    ),
                  ),
                  Table(
                    defaultVerticalAlignment: TableCellVerticalAlignment.middle,
                    columnWidths: {
                      //列宽
                      0: FlexColumnWidth(2.0),
                      1: FlexColumnWidth(1.0),
                      2: FlexColumnWidth(1.0),
                      3: FlexColumnWidth(2.0),
                    },
                    border: TableBorder.all(
                      color: Colors.grey,
                      width: 1.0,
                      style: BorderStyle.solid,
                    ),
                    children: getTableList(context),
                  ),
                  Container(
                    margin: EdgeInsets.all(8),
                    alignment: Alignment.centerLeft,
                    child: Text(
                      "关键物料信息",
                      style:
                      TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
                    ),
                  ),
                  Table(
                    defaultVerticalAlignment: TableCellVerticalAlignment.middle,
                    columnWidths: {
                      //列宽
                      0: FlexColumnWidth(2.0),
                      1: FlexColumnWidth(1.0),
                      2: FlexColumnWidth(1.0),
                      3: FlexColumnWidth(2.0),
                    },
                    border: TableBorder.all(
                      color: Colors.grey,
                      width: 1.0,
                      style: BorderStyle.solid,
                    ),
                    children: getCruxTableList(context),
                  ),
                ],
              ),
            ),
          ),
        ));
  }

  List<TableRow> getTableList(BuildContext context) {
    List<TableRow> tempView = [];
    tempView.add(TableRow(
        children: [
          //增加行高
          SizedBox(
            height: 40,
            child: Align(
              alignment: Alignment.center,
              child: Text(
                '物料料号',
                style: TextStyle(
                  color: theme_blue.toColor(),
                ),
              ),
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: Text(
              '物料类型',
              style: TextStyle(
                color: theme_blue.toColor(),
              ),
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: Text(
              '单位',
              style: TextStyle(
                color: theme_blue.toColor(),
              ),
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: Text(
              '物料批号',
              style: TextStyle(
                color: theme_blue.toColor(),
              ),
            ),
          ),
        ],
        //第一行样式 添加背景色
        decoration: BoxDecoration(
          color: table_head.toColor(),
        )));
    for (int i = 0; i < logic.mainLotList.length; i++) {
      LotBOMLINELIST element = logic.mainLotList[i];
      // logic.editCtlList.add(TextEditingController());
      tempView.add(TableRow(children: [
        //增加行高
        SizedBox(
          height: 40,
          child: Align(
            alignment: Alignment.center,
            child: Text(
              element.mATERIALNAME ?? '',
              style: TextStyle(
                color: text_black.toColor(),
              ),
            ),
          ),
        ),
        Align(
          alignment: Alignment.center,
          child: Text(
            element.mATERIALTYPE ?? '',
            style: TextStyle(
              color: text_black.toColor(),
            ),
          ),
        ),
        Align(
          alignment: Alignment.center,
          child: Text(
            element.uOMID ?? '',
            style: TextStyle(
              color: text_black.toColor(),
            ),
          ),
        ),
        Align(
          alignment: Alignment.topCenter,
          child: Container(
            padding: EdgeInsets.only(bottom: 4),
            child: TextField(
              decoration: InputDecoration(
                border: new UnderlineInputBorder(
                    borderSide: new BorderSide(color: Colors.red)),
                hintText: '请扫描验证',
                hintStyle: TextStyle(
                  fontSize: 14,
                ),
              ),
              onChanged: (value) {
                element.MLOTID = value;
              },
            ),
          ),
        ),
      ]));
    }
    return tempView;
  }

  List<TableRow> getCruxTableList(BuildContext context) {
    List<TableRow> tempView = [];
    tempView.add(TableRow(
        children: [
          //增加行高
          SizedBox(
            height: 40,
            child: Align(
              alignment: Alignment.center,
              child: Text(
                '物料料号',
                style: TextStyle(
                  color: theme_blue.toColor(),
                ),
              ),
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: Text(
              '物料类型',
              style: TextStyle(
                color: theme_blue.toColor(),
              ),
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: Text(
              '单位',
              style: TextStyle(
                color: theme_blue.toColor(),
              ),
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: Text(
              '物料批号',
              style: TextStyle(
                color: theme_blue.toColor(),
              ),
            ),
          ),
        ],
        //第一行样式 添加背景色
        decoration: BoxDecoration(
          color: table_head.toColor(),
        )));
    for (int i = 0; i < logic.stepLotList.length; i++) {
      LotBOMLINELIST element = logic.stepLotList[i];
      // logic.editCtlList.add(TextEditingController());
      tempView.add(TableRow(children: [
        //增加行高
        SizedBox(
          height: 40,
          child: Align(
            alignment: Alignment.center,
            child: Text(
              element.mATERIALNAME ?? '',
              style: TextStyle(
                color: text_black.toColor(),
              ),
            ),
          ),
        ),
        Align(
          alignment: Alignment.center,
          child: Text(
            element.mATERIALTYPE ?? '',
            style: TextStyle(
              color: text_black.toColor(),
            ),
          ),
        ),
        Align(
          alignment: Alignment.center,
          child: Text(
            element.uOMID ?? '',
            style: TextStyle(
              color: text_black.toColor(),
            ),
          ),
        ),
        Align(
          alignment: Alignment.topCenter,
          child: Container(
            padding: EdgeInsets.only(bottom: 4),
            child: TextField(
              decoration: InputDecoration(
                border: new UnderlineInputBorder(
                    borderSide: new BorderSide(color: Colors.red)),
                hintText: '请扫描验证',
                hintStyle: TextStyle(
                  fontSize: 14,
                ),
              ),
              onChanged: (value) {
                element.MLOTID = value;
                // Get.snackbar('提示', value,
                //             colorText: Colors.white, backgroundColor: Colors.black87);
              },
            ),
          ),
        ),
      ]));
    }
    return tempView;
  }
}
